//==========================================================================
// Copyright (c) 2000-2008,  Elastos, Inc.  All Rights Reserved.
//==========================================================================
// win32.h
//
// Pull in standard Win32 declarations
#if _MSC_VER > 1000
#    pragma once
#endif

#ifndef __WINCE_H_
#define __WINCE_H_

#ifdef __cplusplus
extern "C" {
#endif

// -------- DECLSPEC_NORETURN --------------------------
#ifdef __GNUC__
#    define DECLSPEC_NORETURN __declspec(noreturn)
#elif defined(_MSVC)
#    define DECLSPEC_NORETURN
#else
#    error Deinfine your DECLSPEC_NORETURN.
#endif

//----------__int8, __int16, __int32, __int64 -----------

#if defined(_MSC_VER)
/* nothing to do */
#elif defined (__i386__) || defined (__arm__)
#    ifndef __int8
#        define __int8      char
#endif
#    ifndef __int16
#        define __int16     short
#endif
#    ifndef __int32
#        define __int32     int
#endif
#    ifndef __int64
#        define __int64     long long
#        define __uint64    unsigned long long
#endif

#else
#error Define __intN for your architecture.
#endif

//--------------stdcall, cdecl ---------------------------
#if defined(_MSC_VER)
/* nothing to do */
#elif defined(_GNUC) && defined(__i386__)
#    ifndef __stdcall
#        define __stdcall __attribute__((stdcall))
#endif
#    ifndef __cdecl
#        define __cdecl __attribute__((cdecl))
#endif
#else
#    ifdef __arm__
#        ifndef __stdcall
#            define __stdcall
#endif
#        ifndef __cdecl
#            define __cdecl
#endif
#    else
#        error Define your __cdecl and __stdcall
#endif
#endif

#if defined(_WIN64)
 typedef unsigned __int64 ULONG_PTR;
#else
 typedef unsigned long ULONG_PTR;
#endif

// -------------WINAPI, WINBASEAPI ----------------------
#define WINAPI      __stdcall
#define CALLBACK    __stdcall
#define WINBASEAPI  __declspec(dllimport)

//#define assert(exp)

typedef char                CHAR;
typedef short               SHORT;
typedef int                 INT;
typedef long                LONG;
typedef void                VOID;
typedef unsigned long       SIZE_T;

typedef unsigned char       UCHAR;
typedef unsigned short      USHORT;
typedef unsigned int        UINT;
typedef unsigned long       ULONG;

typedef __int8              INT8;
typedef __int16             INT16;
typedef __int32             INT32;
typedef __int64             INT64;

typedef unsigned __int8     UINT8;
typedef unsigned __int16    UINT16;
typedef unsigned __int32    UINT32;
typedef unsigned __int64    UINT64;

typedef INT                 BOOL;
typedef UINT8               BYTE;
//typedef unsigned short      wchar_t;
typedef wchar_t             WCHAR;

typedef void               *HANDLE;
typedef void               *PVOID;
typedef LONG                LRESULT;

typedef VOID        *LPVOID;
typedef const void*  LPCVOID;
typedef CHAR        *PCHAR,  *LPCHAR;
typedef WCHAR       *PWCHAR, *LPWCHAR;
typedef wchar_t     *PTSTR,  *LPTSTR;

typedef CHAR        *PSTR,   *LPSTR;
typedef WCHAR       *PWSTR,  *LPWSTR;
typedef const CHAR  *PCSTR,  *LPCSTR;
typedef const WCHAR *PCWSTR, *LPCWSTR;
//typedef const wchar_t        *LPCTSTR;

typedef unsigned char   *LPBYTE;

typedef long LONG_PTR, *PLONG_PTR;

typedef unsigned short  WORD;
typedef unsigned long   DWORD;
typedef DWORD          *PDWORD;
typedef const void     *PCVOID;

typedef DWORD          *LPDWORD;

#define INVALID_HANDLE_VALUE ((HANDLE)(LONG_PTR)-1)

//#ifndef INLINE
//#   ifdef _MSC_VER
//#       define INLINE __inline
//#   elif defined(_GNUC)
//#       ifdef __cplusplus
//#           define INLINE inline
//#       else
//#           define INLINE inline static
//#       endif
//#   endif
//#endif
// -----------for priority ranke--------------------------------

#define NORMAL_PRIORITY_CLASS        0x00000020
#define IDLE_PRIORITY_CLASS          0x00000040
#define HIGH_PRIORITY_CLASS          0x00000080
#define REALTIME_PRIORITY_CLASS      0x00000100

// -----------for priority --------------------------------------
#define MAXLONG                      0x7fffffff
#define THREAD_BASE_PRIORITY_LOWRT   15  // value that gets a thread to
// LowRealtime-1
#define THREAD_BASE_PRIORITY_MAX     2   // maximum thread base priority boost
#define THREAD_BASE_PRIORITY_MIN     -2  // minimum thread base priority boost
#define THREAD_BASE_PRIORITY_IDLE    -15 // value that gets a thread to idle

#define THREAD_PRIORITY_TIME_CRITICAL   THREAD_BASE_PRIORITY_LOWRT
#define THREAD_PRIORITY_IDLE            THREAD_BASE_PRIORITY_IDLE
#define THREAD_PRIORITY_ERROR_RETURN    (MAXLONG)

#define THREAD_PRIORITY_LOWEST          THREAD_BASE_PRIORITY_MIN
#define THREAD_PRIORITY_BELOW_NORMAL    (THREAD_PRIORITY_LOWEST+1)
#define THREAD_PRIORITY_NORMAL          0
#define THREAD_PRIORITY_HIGHEST         THREAD_BASE_PRIORITY_MAX
#define THREAD_PRIORITY_ABOVE_NORMAL    (THREAD_PRIORITY_HIGHEST-1)

// ---------- critical section ---------------------------------

typedef struct _LIST_ENTRY {
    struct _LIST_ENTRY *Flink;
    struct _LIST_ENTRY *Blink;
} LIST_ENTRY,*PLIST_ENTRY;

struct _WIN_CRITICAL_SECTION;

typedef struct _CRITICAL_SECTION_DEBUG {
    WORD Type;
    WORD CreatorBackTraceIndex;
    struct _WIN_CRITICAL_SECTION *CriticalSection;
    LIST_ENTRY ProcessLocksList;
    DWORD EntryCount;
    DWORD ContentionCount;
    DWORD Spare [2];
} CRITICAL_SECTION_DEBUG,*PCRITICAL_SECTION_DEBUG;

typedef struct _WIN_CRITICAL_SECTION {
    PCRITICAL_SECTION_DEBUG DebugInfo;
    LONG LockCount;
    LONG RecursionCount;
    HANDLE OwningThread;
    HANDLE LockSemaphore;
    DWORD SpinCount;
} WIN_CRITICAL_SECTION,*PWIN_CRITICAL_SECTION,*LPWIN_CRITICAL_SECTION;

// -----------for event ------------------------------------------
typedef struct _SECURITY_ATTRIBUTES {
  DWORD  nLength;
  LPVOID lpSecurityDescriptor;
  BOOL   bInheritHandle;
} SECURITY_ATTRIBUTES, *PSECURITY_ATTRIBUTES;
typedef struct _SECURITY_ATTRIBUTES* LPSECURITY_ATTRIBUTES;

// ----------- for process ---------------------------------------
typedef struct _STARTUPINFOW {
    DWORD   cb;
    LPWSTR  lpReserved;
    LPWSTR  lpDesktop;
    LPWSTR  lpTitle;
    DWORD   dwX;
    DWORD   dwY;
    DWORD   dwXSize;
    DWORD   dwYSize;
    DWORD   dwXCountChars;
    DWORD   dwYCountChars;
    DWORD   dwFillAttribute;
    DWORD   dwFlags;
    WORD    wShowWindow;
    WORD    cbReserved2;
    BYTE*   lpReserved2;
    HANDLE  hStdInput;
    HANDLE  hStdOutput;
    HANDLE  hStdError;
}STARTUPINFOW,*LPSTARTUPINFOW;
typedef LPSTARTUPINFOW LPSTARTUPINFO;

typedef struct _PROCESS_INFORMATION {
    HANDLE hProcess;
    HANDLE hThread;
    DWORD dwProcessId;
    DWORD dwThreadId;
} PROCESS_INFORMATION,*PPROCESS_INFORMATION,*LPPROCESS_INFORMATION;

// -----------for lifetime ------------------------------------------
typedef struct _SYSTEMTIME {
    WORD wYear;
    WORD wMonth;
    WORD wDayOfWeek;
    WORD wDay;
    WORD wHour;
    WORD wMinute;
    WORD wSecond;
    WORD wMilliseconds;
} SYSTEMTIME, *PSYSTEMTIME, *LPSYSTEMTIME;

typedef struct _FILETIME {
    DWORD dwLowDateTime;
    DWORD dwHighDateTime;
} FILETIME, *PFILETIME, *LPFILETIME;

// --------- for virtual memory allocation --------------------------

#define PAGE_NOACCESS          0x01
#define PAGE_READONLY          0x02
#define PAGE_READWRITE         0x04
#define PAGE_WRITECOPY         0x08
#define PAGE_EXECUTE           0x10
#define PAGE_EXECUTE_READ      0x20
#define PAGE_EXECUTE_READWRITE 0x40
#define PAGE_EXECUTE_WRITECOPY 0x80
#define PAGE_GUARD             0x100
#define PAGE_NOCACHE           0x200

#define MEM_COMMIT      0x1000
#define MEM_RESERVE     0x2000
#define MEM_DECOMMIT    0x4000
#define MEM_RELEASE     0x8000
#define MEM_FREE        0x10000
#define MEM_PRIVATE     0x20000
#define MEM_MAPPED      0x40000
#define MEM_RESET       0x80000
#define MEM_TOP_DOWN    0x100000

typedef struct _MEMORY_BASIC_INFORMATION {
PVOID BaseAddress;
PVOID AllocationBase;
DWORD AllocationProtect;
DWORD RegionSize;
DWORD State;
DWORD Protect;
DWORD Type;
} MEMORY_BASIC_INFORMATION;
typedef MEMORY_BASIC_INFORMATION *PMEMORY_BASIC_INFORMATION;

//------------------------for crt-------------------------------
#ifndef _VA_LIST_DEFINED
#   if defined(_GNUC)
#       define va_list __builtin_va_list
#       define va_start(v, args) __builtin_stdarg_start(v, args)
#       define va_end  __builtin_va_end
#       define va_arg  __builtin_va_arg
#   elif defined(_MSVC)
#       define _INTSIZEOF(n)   ((sizeof(n) + sizeof(int) - 1) & ~(sizeof(int) - 1))
#       define va_list unsigned char*
#       define va_start(ap, v) (ap = (va_list)&v + _INTSIZEOF(v))
#       define va_arg(ap, t)   (*(t *)((ap += _INTSIZEOF(t)) - _INTSIZEOF(t)))
#       define va_end(ap)      (ap = (va_list)0)
#   else
//#       error define your own compiler and va_list_define.
#endif
#   define _VA_LIST_DEFINED
#endif

#ifdef _GNUC
#   ifdef _arm
typedef unsigned long size_t;
#   else
typedef unsigned int size_t;
#endif
//_arm
#else
typedef unsigned int size_t;
#endif //_GNUC

int vprintf( const char *format, va_list argptr );
//int swprintf( wchar_t *buffer, const wchar_t *format [, argument] ... );
int _vsnwprintf( wchar_t *buffer, size_t count, const wchar_t *format, va_list argptr );
void *memset(void *dest, int c, size_t count);
int _putws(const wchar_t* string);
//wchar_t *_wfullpath(wchar_t *absPath,const wchar_t *relPath,size_t maxLength);
wchar_t *wcscat( wchar_t *strDestination, const wchar_t *strSource );
wchar_t *wcschr( const wchar_t *string, wchar_t c );
wchar_t *wcsrchr( const wchar_t *string, wchar_t c );
wchar_t *wcscpy( wchar_t *strDestination, const wchar_t *strSource );
size_t wcslen( const wchar_t *string );
size_t wcstombs( char *mbstr, const wchar_t *wcstr, size_t count );
int getchar(void);
void *memcpy(void* dest,const void* src, size_t count);


#if defined (_GNUC)
#define _alloca __builtin_alloca
#else
void *  __cdecl _alloca(size_t);
#endif

// --------------------------------------------------------------
#define NO_ERROR 0

#define DLL_PROCESS_DETACH 0
#define DLL_PROCESS_ATTACH 1
#define DLL_THREAD_ATTACH  2
#define DLL_THREAD_DETACH  3

// ---------- for error -------------------------------------------
WINBASEAPI VOID WINAPI SetLastError(DWORD);
WINBASEAPI DWORD WINAPI GetLastError(VOID);

// ---------- for critical section ---------------------------------

WINBASEAPI VOID WINAPI InitializeCriticalSection(LPWIN_CRITICAL_SECTION);
WINBASEAPI VOID WINAPI EnterCriticalSection(LPWIN_CRITICAL_SECTION);
WINBASEAPI BOOL WINAPI TryEnterCriticalSection(LPWIN_CRITICAL_SECTION);
WINBASEAPI VOID WINAPI LeaveCriticalSection(LPWIN_CRITICAL_SECTION);
WINBASEAPI VOID WINAPI DeleteCriticalSection(LPWIN_CRITICAL_SECTION);

// ---------- for handle --------------------------------------------
#define STATUS_WAIT_0        ((DWORD)0x00000000L)
#define WAIT_FAILED          (DWORD)0xFFFFFFFF
#define WAIT_OBJECT_0        ((STATUS_WAIT_0 ) + 0 )

#define WAIT_TIMEOUT ((DWORD)0x00000102L)
#define WAIT_ABANDONED ((DWORD)0x00000080L)
#define WAIT_IO_COMPLETION ((DWORD)0x000000c0L)

#define MAXIMUM_WAIT_OBJECTS 64

WINBASEAPI BOOL   WINAPI CloseHandle(HANDLE);
WINBASEAPI DWORD  WINAPI WaitForSingleObject(HANDLE, DWORD);

// -----------for event ---------------------------------------------
#define EVENT_PULSE     1
#define EVENT_RESET     2
#define EVENT_SET       3

WINBASEAPI HANDLE WINAPI CreateEventW(LPSECURITY_ATTRIBUTES,BOOL,BOOL,LPCWSTR);
WINBASEAPI HANDLE WINAPI OpenEventW(DWORD,BOOL,LPCWSTR);
WINBASEAPI BOOL WINAPI EventModify(HANDLE,DWORD);

_inline BOOL PulseEvent(HANDLE h) {
	return EventModify(h,EVENT_PULSE);
}
_inline BOOL ResetEvent(HANDLE h) {
	return EventModify(h,EVENT_RESET);
}
_inline BOOL SetEvent(HANDLE h) {
	return EventModify(h,EVENT_SET);
}

// ----------- for mutex ---------------------------------------------
#define MUTEX_ALL_ACCESS 0x001F0001L
WINBASEAPI HANDLE WINAPI CreateMutexW(LPSECURITY_ATTRIBUTES,BOOL,LPCWSTR);
WINBASEAPI BOOL   WINAPI ReleaseMutex(HANDLE);

// -----------for process --------------------------------------------
#define STILL_ACTIVE (259)
WINBASEAPI BOOL WINAPI TerminateProcess(HANDLE, DWORD);
#define ExitProcess(code)   TerminateProcess (GetCurrentProcess (), (code))
WINBASEAPI BOOL WINAPI CreateProcessW(LPCWSTR,LPCWSTR,
                                LPSECURITY_ATTRIBUTES,
                                LPSECURITY_ATTRIBUTES,
                                BOOL,DWORD,LPVOID,LPCWSTR,
                                LPSTARTUPINFOW,
                                LPPROCESS_INFORMATION);

// -----------for module --------------------------------------------
typedef struct _MODULEINFO {
    LPVOID lpBaseOfDll;
    DWORD  SizeOfImage;
    LPVOID EntryPoint;
} MODULEINFO,*LPMODULEINFO;

typedef HANDLE    HINSTANCE;
typedef HINSTANCE HMODULE;
typedef HANDLE    HRSRC;
typedef HANDLE    HGLOBAL;
typedef int (WINAPI *FARPROC)();

WINBASEAPI HINSTANCE WINAPI LoadLibraryW(LPCWSTR);
WINBASEAPI BOOL    WINAPI FreeLibrary(HMODULE);
WINBASEAPI HMODULE WINAPI GetModuleHandleW(LPCWSTR);
WINBASEAPI FARPROC WINAPI GetProcAddressA(HMODULE,LPCSTR);
WINBASEAPI BOOL    WINAPI GetModuleInformation(HANDLE,HMODULE,LPMODULEINFO,DWORD);
WINBASEAPI DWORD   WINAPI GetModuleFileNameW(HINSTANCE,LPWSTR,DWORD);
WINBASEAPI HRSRC   WINAPI FindResourceW(HMODULE,LPCWSTR,LPCWSTR);
WINBASEAPI DWORD   WINAPI SizeofResource(HMODULE,HRSRC);
WINBASEAPI HGLOBAL WINAPI LoadResource(HMODULE,HRSRC);
_inline LPVOID LockResource(HGLOBAL hResData) {return ((LPVOID)hResData);}



#define MAX_PATH  260
#define TH32CS_SNAPMODULE   0x00000008

typedef struct tagMODULEENTRY32 {
  DWORD dwSize;
  DWORD th32ModuleID;
  DWORD th32ProcessID;
  DWORD GlblcntUsage;
  DWORD ProccntUsage;
  BYTE *modBaseAddr;
  DWORD modBaseSize;
  HMODULE hModule;
  WCHAR szModule[MAX_PATH];
  WCHAR szExePath[MAX_PATH];
  DWORD dwFlags;
} MODULEENTRY32, *PMODULEENTRY32, *LPMODULEENTRY32;

WINBASEAPI HANDLE WINAPI CreateToolhelp32Snapshot(DWORD, DWORD);
WINBASEAPI BOOL   WINAPI CloseToolhelp32Snapshot(HANDLE);
WINBASEAPI BOOL   WINAPI Module32First(HANDLE, LPMODULEENTRY32);
WINBASEAPI BOOL   WINAPI Module32Next(HANDLE, LPMODULEENTRY32);

// ----------- for Time -------------------------------------------
WINBASEAPI BOOL   WINAPI GetProcessTimes(HANDLE,
                                 LPFILETIME,LPFILETIME,
                                 LPFILETIME,LPFILETIME);
WINBASEAPI BOOL   WINAPI GetThreadTimes(HANDLE,
                                 LPFILETIME,LPFILETIME,
                                 LPFILETIME,LPFILETIME);
WINBASEAPI DWORD  WINAPI GetTickCount();

typedef union _LARGE_INTEGER {
    struct {
        DWORD LowPart ;
        INT64  HighPart;
    };
    INT64 QuadPart ;
}LARGE_INTEGER ;

WINBASEAPI BOOL WINAPI QueryPerformanceCounter(
                                LARGE_INTEGER *lpPerformanceCount);

WINBASEAPI BOOL WINAPI QueryPerformanceFrequency(
                                LARGE_INTEGER *lpFrequency);

// ------------for thread ---------------------------------------------
#define CREATE_SUSPENDED 0x00000004

typedef DWORD (WINAPI *LPTHREAD_START_ROUTINE)(LPVOID);
DECLSPEC_NORETURN WINBASEAPI VOID WINAPI ExitThread(DWORD);
WINBASEAPI HANDLE WINAPI CreateThread(LPSECURITY_ATTRIBUTES,
                                 DWORD,
                                 LPTHREAD_START_ROUTINE,
                                 PVOID,
                                 DWORD,
                                 PDWORD);
WINBASEAPI BOOL   WINAPI GetExitCodeThread(HANDLE,PDWORD);
WINBASEAPI BOOL   WINAPI TerminateThread(HANDLE,DWORD);
WINBASEAPI DWORD  WINAPI SuspendThread(HANDLE);
WINBASEAPI DWORD  WINAPI ResumeThread(HANDLE);


WINBASEAPI BOOL   WINAPI SetThreadPriority(HANDLE,INT);
WINBASEAPI INT    WINAPI GetThreadPriority(HANDLE);

// ------------ for get current content ---------------------------------
#define SH_CURTHREAD     1
#define SH_CURPROC       2
#define PUserKData       ((LPBYTE)0xFFFFC800)
#define SYSHANDLE_OFFSET 0x004
#define SYS_HANDLE_BASE	 64

_inline HANDLE GetCurrentThread(VOID) {
    return ((HANDLE)(SH_CURTHREAD+SYS_HANDLE_BASE));
}
_inline HANDLE GetCurrentProcess(VOID) {
    return ((HANDLE)(SH_CURPROC+SYS_HANDLE_BASE));
}
_inline DWORD GetCurrentThreadId(VOID) {
	return ((DWORD)(((HANDLE *)(PUserKData+SYSHANDLE_OFFSET))[SH_CURTHREAD]));
}
_inline DWORD GetCurrentProcessId(VOID) {
	return ((DWORD)(((HANDLE *)(PUserKData+SYSHANDLE_OFFSET))[SH_CURPROC]));
}

//------------ for thread local storage --------------------------------
#define TLS_FUNCALLOC   0
#define TLS_FUNCFREE    1

WINBASEAPI DWORD  WINAPI TlsCall(DWORD,DWORD);
WINBASEAPI LPVOID WINAPI TlsGetValue(DWORD);
WINBASEAPI BOOL   WINAPI TlsSetValue(DWORD,LPVOID);

_inline DWORD WINAPI TlsAlloc(void) {
    return TlsCall(TLS_FUNCALLOC, 0);
}
_inline BOOL WINAPI TlsFree(DWORD dwTlsIndex) {
    return TlsCall(TLS_FUNCFREE, dwTlsIndex);
}

// ------------ for system time ----------------------------------------
WINBASEAPI DWORD  WINAPI GetTickCount(VOID);
WINBASEAPI void   WINAPI GetSystemTime(PVOID);
WINBASEAPI BOOL   WINAPI SetSystemTime(const PSYSTEMTIME );

WINBASEAPI VOID   WINAPI Sleep(DWORD);

typedef struct _MEMORYSTATUS {
    DWORD dwLength;
    DWORD dwMemoryLoad;
    SIZE_T dwTotalPhys;
    SIZE_T dwAvailPhys;
    SIZE_T dwTotalPageFile;
    SIZE_T dwAvailPageFile;
    SIZE_T dwTotalVirtual;
    SIZE_T dwAvailVirtual;
} MEMORYSTATUS,  *LPMEMORYSTATUS;

WINBASEAPI VOID   WINAPI GlobalMemoryStatus(LPMEMORYSTATUS);

// ------------- for virtual memory allocation --------------------------
WINBASEAPI LPVOID WINAPI VirtualAlloc(LPVOID,DWORD,DWORD,DWORD);
WINBASEAPI BOOL   WINAPI VirtualFree(LPVOID, DWORD, DWORD);
WINBASEAPI BOOL   WINAPI VirtualProtect(LPVOID,DWORD,DWORD,PDWORD);
WINBASEAPI DWORD  WINAPI VirtualQuery(LPCVOID,PMEMORY_BASIC_INFORMATION,DWORD);

//-------------- for sharedmemory ---------------------------------------

#define FILE_MAP_WRITE   0x0002
#define FILE_MAP_READ    0x0004

WINBASEAPI HANDLE WINAPI CreateFileMappingW(HANDLE,
                                        LPSECURITY_ATTRIBUTES,
                                        DWORD, DWORD, DWORD,
                                        LPCWSTR);
WINBASEAPI LPVOID WINAPI MapViewOfFile(HANDLE, DWORD, DWORD, DWORD,DWORD);
WINBASEAPI BOOL   WINAPI UnmapViewOfFile(LPCVOID);

//-------------- for ipc ------------------------------------------------
#define MSGQUEUE_NOPRECOMMIT    0x00000001
#define MSGQUEUE_ALLOW_BROKEN   0x00000002

typedef struct MSGQUEUEOPTIONS_OS {
    DWORD dwSize;                     // size of the structure
    DWORD dwFlags;                    // behavior of message queue
    DWORD dwMaxMessages;              // max # of msgs in queue
    DWORD cbMaxMessage;               // max size of msg
    BOOL  bReadAccess;                // read access requested
} MSGQUEUEOPTIONS, *LPMSGQUEUEOPTIONS, *PMSGQUEUEOPTIONS;

WINBASEAPI HANDLE WINAPI CreateMsgQueue(LPCWSTR,LPMSGQUEUEOPTIONS);
WINBASEAPI HANDLE WINAPI OpenMsgQueue(HANDLE,HANDLE,LPMSGQUEUEOPTIONS);
WINBASEAPI BOOL   WINAPI ReadMsgQueue(HANDLE,LPVOID,DWORD,LPDWORD,DWORD,DWORD*);
WINBASEAPI BOOL   WINAPI WriteMsgQueue(HANDLE,LPVOID,DWORD,DWORD,DWORD);
//WINBASEAPI _ELASTOS Boolean   WINAPI GetMsgQueueInfo(HANDLE,LPMSGQUEUEINFO);
WINBASEAPI BOOL   WINAPI CloseMsgQueue(HANDLE);
//---------------for heap memory alloction -------------------------------
void *malloc(size_t size);
void *realloc(void* memblock, size_t size);
void free(void* memblock);


WINBASEAPI
LPWSTR
WINAPI
GetCommandLineW(
    VOID
    );

// ---- accesss right --------------------------------------------
#define ALL_ACCESS_RIGHT  0x00100FFF
#define THREAD_ALL_ACCESS 0x001F03FF
// ---- error value ----------------------------------------------

#define ERROR_SUCCESS               0L
#define ERROR_FILE_NOT_FOUND        2L
#define ERROR_PATH_NOT_FOUND        3L
#define ERROR_TOO_MANY_OPEN_FILES   4L
#define ERROR_ACCESS_DENIED         5L
#define ERROR_INVALID_HANDLE        6L
#define ERROR_NOT_ENOUGH_MEMORY     8L
#define ERROR_BAD_FORMAT            11L
#define ERROR_INVALID_ACCESS        12L
#define ERROR_INVALID_DATA          13L
#define ERROR_OUTOFMEMORY           14L
#define ERROR_INVALID_DRIVE         15L
#define ERROR_NO_MORE_FILES         18L
#define ERROR_WRITE_PROTECT         19L
#define ERROR_NOT_READY             21L
#define ERROR_BAD_LENGTH            24L
#define ERROR_WRITE_FAULT           29L
#define ERROR_READ_FAULT            30L
#define ERROR_SHARING_VIOLATION     32L
#define ERROR_LOCK_VIOLATION        33L
#define ERROR_HANDLE_EOF            38L
#define ERROR_HANDLE_DISK_FULL      39L
#define ERROR_NOT_SUPPORTED         50L
#define ERROR_DUP_NAME              52L
#define ERROR_BAD_NETPATH           53L
#define ERROR_DEV_NOT_EXIST         55L
#define ERROR_BAD_NET_NAME          67L
#define ERROR_FILE_EXISTS           80L
#define ERROR_CANNOT_MAKE           82L
#define ERROR_INVALID_PARAMETER     87L
#define ERROR_NET_WRITE_FAULT       88L
#define ERROR_DRIVE_LOCKED          108L
#define ERROR_BROKEN_PIPE           109L
#define ERROR_OPEN_FAILED           110L
#define ERROR_BUFFER_OVERFLOW       111L
#define ERROR_DISK_FULL             112L
#define ERROR_CALL_NOT_IMPLEMENTED  120L
#define ERROR_SEM_TIMEOUT           121L
#define ERROR_INSUFFICIENT_BUFFER   122L
#define ERROR_INVALID_NAME          123L
#define ERROR_MOD_NOT_FOUND         126L
#define ERROR_PROC_NOT_FOUND        127L
#define ERROR_NEGATIVE_SEEK         131L
#define ERROR_SEEK_ON_DEVICE        132L
#define ERROR_DIR_IS_NOT_EMPTY      145L
#define ERROR_SIGNAL_REFUSED        156L
#define ERROR_NOT_LOCKED            158L
#define ERROR_BAD_PATHNAME          161L
#define ERROR_ALREADY_EXISTS        183L
#define ERROR_INVALID_EXE_SIGNATURE 191L
#define ERROR_EXE_MARKED_INVALID    192L
#define ERROR_BAD_EXE_FORMAT        193L
#define ERROR_ENVVAR_NOT_FOUND      203L
#define ERROR_FILENAME_EXCED_RANGE  206L
#define ERROR_PIPE_BUSY             231L
#define ERROR_NO_DATA               232L
#define ERROR_PIPE_NOT_CONNECTED    233L
#define ERROR_MORE_DATA             234L
#define ERROR_NO_MORE_ITEMS         259L
#define ERROR_DIRECTORY             267L
#define ERROR_NOT_OWNER             288L
#define ERROR_PARTIAL_COPY          299L
#define ERROR_INVALID_ADDRESS       487L
#define ERROR_ARITHMETIC_OVERFLOW   534L
#define ERROR_PIPE_CONNECTED        535L
#define ERROR_OPERATION_ABORTED     995L
#define ERROR_IO_PENDING            997L
#define ERROR_NOACCESS              998L
#define ERROR_STACK_OVERFLOW        1001L
#define ERROR_INVALID_FLAGS         1004L
#define ERROR_UNRECOGNIZED_VOLUME   1005L
#define ERROR_FILE_INVALID          1006L
#define ERROR_PROCESS_ABORTED       1067L
#define ERROR_DLL_INIT_FAILED       1114L
#define ERROR_IO_DEVICE             1117L
#define ERROR_DISK_OPERATION_FAILED 1127L
#define ERROR_POSSIBLE_DEADLOCK     1131L
#define ERROR_NOT_FOUND             1168L
#define ERROR_CANCELLED             1223L
#define ERROR_UNIDENTIFIED_ERROR    1287L
#define ERROR_INTERNAL_ERROR        1359L
#define ERROR_FILE_CORRUPT          1392L
#define ERROR_DISK_CORRUPT          1393L
#define ERROR_WRONG_TARGET_NAME     1396L
#define ERROR_COMMITMENT_LIMIT      1455L
#define ERROR_TIMEOUT               1460L
#define ERROR_RESOURCE_DATA_NOT_FOUND 1812L
#define ERROR_RESOURCE_LANG_NOT_FOUND 1815L
#define ERROR_TAG_NOT_PRESENT       2013L



#ifdef __cplusplus
}
#endif

#endif  //__WINCE_H_
